package com.jfl.interceptor;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * <一句话功能简述>
 *  
 * @author  赵炎
 * @version  [V1.00, 2019年7月15日]
 * @see  [相关类/方法]
 * @since V1.00
 */
public class AuthenticationInterceptor implements HandlerInterceptor
{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
        String token = request.getHeader("token");
        // 如果不是映射到方法直接通过
        if (!(handler instanceof HandlerMethod)) 
        {
            return true;
        }
        HandlerMethod handlerMethod = (HandlerMethod)handler;
        Method method = handlerMethod.getMethod();
        // 检查是否 pass token注释，有则跳过认证
        // if(method.isAnnotationPresent())
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
